#include "StdAfx.h"
#include "DataList.h"

CDataList::CDataList(void)
{
}

CDataList::~CDataList(void)
{
}

BOOL CDataList::CreateEx(
		int nX, int nY, int cx, int cy,
		HWND hParent,
		HINSTANCE hInst
	)
{
	BOOL ret = CBaseWindow::CreateEx(0, _T("SysListView32"), _T(""), 
		LVS_REPORT | WS_CHILD | WS_TABSTOP | LVS_OWNERDATA | LVS_NOCOLUMNHEADER,
		nX, nY, cx, cy, hParent, HMENU(0), hInst);
	return ret;
}

LRESULT CDataList::WndProcExt(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	return ::DefWindowProc(hwnd, uMsg, wParam, lParam);
}

void CDataList::OnDrawItem(LPDRAWITEMSTRUCT lpdis)
{
	CNote* note = m_notesData->at(lpdis->itemID);
	HDC dc = lpdis->hDC;
	RECT rc = lpdis->rcItem;

	if(lpdis->itemState & ODS_SELECTED)
	{
		SetTextColor(dc, GetSysColor(COLOR_HIGHLIGHTTEXT));
		FillRect(dc, &rc, GetSysColorBrush(COLOR_HIGHLIGHT));
	}
	else
	{
		SetTextColor(dc, GetSysColor(COLOR_WINDOWTEXT));
		FillRect(dc, &rc, CreateSolidBrush(note->color));
	}
	DrawText(dc, note->body.c_str(), note->body.length(), &rc, DT_LEFT);
}

void CDataList::OnMeasureItem(LPMEASUREITEMSTRUCT lpmis)
{
	lpmis->itemHeight = 30;
}